package com.atm.servlet;

import com.atm.pojo.User;
import com.atm.service.UserService;
import com.atm.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 跳转修改页面
 */
@WebServlet("/toUpdate")
public class UserToUpdateServlet extends HttpServlet {
    private UserService userService=new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String icno = req.getParameter("icno");
        User userByIcno = userService.getUserByIcno(icno);
        if (userByIcno==null){
            req.getSession().setAttribute("error","此用户不存在");
        }else {
            req.getSession().setAttribute("user",userByIcno);
            resp.sendRedirect("changepage/update.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
